/***************************************************************
 * Name:      CamMain.h
 * Purpose:   Defines Application Frame
 * Author:    Riku Maikola (rpm@ac-mapa.org)
 * Created:   2011-02-17
 * Copyright: Riku Maikola (rpm.ac-mapa.org)
 * License:
 **************************************************************/

#ifndef CAMMAIN_H
#define CAMMAIN_H

#include <wx/sizer.h>
#include <wx/gdicmn.h>
#include <wx/panel.h>
#include <wx/font.h>
#include <wx/colour.h>
#include <wx/settings.h>
#include <wx/string.h>
#include <wx/textctrl.h>
#include <wx/button.h>
#include <wx/toolbar.h>
#include <wx/slider.h>
#include <wx/bitmap.h>
#include <wx/image.h>
#include <wx/icon.h>
#include <wx/statline.h>
#include <wx/spinctrl.h>
#include <wx/notebook.h>
#include <wx/menu.h>
#include <wx/statusbr.h>
#include <wx/frame.h>

#include "sys/time.h"
#include <wx/html/htmlwin.h>
#include "CamApp.h"
#include <wx/filedlg.h>
#include <sys/shm.h>
#include "mImage.h"
#include "mCore.h"
#include "wx/timer.h"
#include <wx/tokenzr.h>
#include <unistd.h>
#include <sys/types.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>

enum
{
    gCycleStart = 1000,
    gCliView,
    gPLAY,
    gSTOP,
    gBuild,
    gScriptView,

    gScriptWindow,

    tGetImage,
    tLoad,
    tSave,
    ReSetup,
    menuLoad,
    menuSave,
    menuSaveAs,
    menuEditCode,
    menuEditWorkDir,
    menuBuild,
    menuBuildRun,
    menuRun,
    ViewLookAtXY,
    ViewLookAtYZ,
    LookAtG54,
    LookAtG55,
    LookAtG56,
    LookAtG57,
    LookAtG58,
    LookAtG59,
    loadImages,
    saveImages,
    imageDeselectALL,
    imageDelElement,
    imageMenuClear,
    G_PathGetPlate,
    G_PathShow,

    f_Copy,
    f_Copy_selected,
    f_Paste,
    f_Clear


};

class Asset
{
    public:
    std::string file;
    int UpdateTime = 0;
};

class CamMain: public wxFrame,public mCore
{
public:
    //CANVAS OBJECTS
    uint Uptime = 0;
    mCanvas * Canvas;
    bool CanvasMouseMove = false;

    wxTextCtrl *ToolEditBox;
    wxTextCtrl *SetupEditBox;

    //***************************//
    wxPoint MP;
    double MX,MY, LMX,LMY,MMX,MMY,RMX,RMY;                 //MOUSE CLICK POSITION
    void Initation();                       //load

    bool Shift=false,Ctrl=false,Alt=false;

private:
    wxTimer m_timer;
    wxTimer update_timer;
    int TimeOfUpdateOfSim = 0;

    std::vector<Asset> AssDir;
    //FUNCTIONS*********//
    virtual void BUTTON( wxCommandEvent& event );

    //menu
    virtual void OnMenu( wxCommandEvent& event );
    virtual void OnMenuEdit( wxCommandEvent& event );
    virtual void OnMenuBuild( wxCommandEvent& event );
    virtual void OnMenuView( wxCommandEvent& event );
    virtual void OnMenuImage( wxCommandEvent& event );
    virtual void OnMenuGpath( wxCommandEvent& event );

    //virtual void iOnSize( wxSizeEvent& event );
    virtual void iWheel( wxMouseEvent& event );
    virtual void iKeyDOWN( wxKeyEvent& event );
    virtual void iKeyUP( wxKeyEvent& event );
    virtual void iMouse( wxMouseEvent& event );
    virtual void iEXE( wxCommandEvent& event );
    virtual void iPaint( wxPaintEvent& event );
    void iOnSize( wxSizeEvent& event );

    //
    void OnSIM();
    void OnScroll( wxScrollEvent& event );
    void OnTimer(wxTimerEvent& event);
    void OnIdle(wxIdleEvent& event);
    void SizeFrame(wxSizeEvent& event);

    void OnTimerUpdate(wxTimerEvent& event);

protected:
    wxWindow * iPanel;
    bool CLI=false;

    //** simulation
    wxWindow * SimulationWindow;
    wxTextCtrl *SimulationInfo;
    wxButton * SimulationPlay; //simu start
    wxButton * SimulationStop; //simu stop
    wxSlider * SimulationPosition;

    //**Cli window
    wxWindow * CliWindow;
    wxButton* BCliView;
    wxTextCtrl* iPAST;
    wxTextCtrl* iCLI;

    //**
    wxButton* m_button51;
    wxStaticLine* m_staticline25;
    wxPanel* Setup;
    wxButton* m_button5;

    wxMenuBar* MenuBar;
    wxMenu* ProjectMenu;
    wxMenu* EditorMenu;
    wxMenu* BuildMenu;
    wxMenu* ViewMenu;
    wxMenu* ViewLookFromMenu;
    wxMenu* ViewLookAtMenu;
    wxMenu* ImagesMenu;
    wxMenu* G_PathMenu;
    wxStatusBar* statusBar;

    virtual void OnClose( wxCloseEvent& event )
    {
        event.Skip();
    }

    void OnPopupClick(wxCommandEvent &evt);
    void OnListRightClick();
    void Functions(uint id);

public:

    CamMain( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = wxT("Gpath"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( 1000,600 ), long style = wxDEFAULT_FRAME_STYLE|wxTAB_TRAVERSAL );
    ~CamMain();

};
#endif // CHAMFERMAIN_H
